<template>
  <div class="role-selector">
    <div class="title">已收到您的听力文稿，为多人对话形式，请确认各角色性别！</div>

    <div class="role-row">
      <div>
        <div class="role-row" v-for="(user, index) in state.roleList" :key="index">
          <span class="user-name">{{ user.people }}：</span>
          <div class="sexCheck">
            <span @click="sexSelect('男', index)" :class="`${user.sex == '男' && 'spanCheck'}`">男</span>
            <span @click="sexSelect('女', index)" :class="`${user.sex == '女' && 'spanCheck'}`">女</span>
          </div>
        </div>
      </div>

      <div class="submit" @click="confirm">确定</div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref, watch } from 'vue';

const props = defineProps({
  hearingRoleList: Array as any,
});

// watch(
//   () => props.hearingRoleList,
//   (newVal: any) => {
//     state.roleList = newVal;
//   },
//   {
//     immediate: true,
//   },
// );

const state = reactive({
  roleList: [] as any,
});

watch(
  () => props.hearingRoleList,
  (newVal: any) => {
    console.log('newVal', newVal);
    state.roleList = newVal;
  },
  {
    immediate: true,
    deep: true,
  },
);

const pGender = ref('男');
const mGender = ref('女');

const sexSelect = (key: any, value: any) => {
  state.roleList[value].sex = key;
};

const emit = defineEmits<{
  (e: 'confirm', genders: { P: string; M: string }): void;
}>();

const confirm = () => {
  emit('confirm', state.roleList);
};
</script>

<style lang="scss" scoped>
.role-selector {
  .role-row {
    display: flex;
    justify-content: space-between;
    align-items: end;
  }
  .title {
    font-family: PingFangSC, PingFang SC;
    font-weight: 400;
    font-size: 14px;
    color: #1a1a1a;
    line-height: 22px;
    text-align: left;
    font-style: normal;
  }

  .submit {
    width: 60px;
    height: 32px;
    background: #ff8500;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;

    font-family: PingFangSC, PingFang SC;
    font-weight: 400;
    font-size: 14px;
    color: #ffffff;
    line-height: 24px;
    text-align: right;
    font-style: normal;
  }
}

.role-row {
  margin-top: 8px;
  display: flex;
  align-items: center;
  user-select: none;

  .user-name {
    // border: 1px solid red;
    display: block;
    width: 50px;
  }

  .sexCheck {
    display: flex;
    align-items: center;

    span {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 46px;
      height: 32px;
      background: #ffffff;
      border-radius: 8px;
      border: 1px solid #eeeeee;
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      font-size: 14px;
      color: #6a6a6a;
      line-height: 20px;
      text-align: right;
      font-style: normal;
      cursor: pointer;
      margin-right: 8px;
    }

    .spanCheck {
      background: rgba(255, 133, 0, 0.1);
      border-radius: 8px;
      border: 1px solid #ff8500;

      font-family: PingFangSC, PingFang SC;
      font-weight: 500;
      font-size: 14px;
      color: #ff8500;
    }
  }
}
</style>
